﻿using System;
using System.Data;
using System.Xml;

namespace MSHelpLib
{
    /// <summary>
    /// 
    /// </summary>
	public delegate void SearchResultsRowChangeEventHandler(object sender, SearchResultsRowChangeEvent e);

    /// <summary>
    /// 
    /// </summary>
	[System.Diagnostics.DebuggerStepThrough()]
	public class SearchResultsTable : DataTable, System.Collections.IEnumerable 
	{            
		private DataColumn columnIndex;            
		private DataColumn columnTitle;            
		private DataColumn columnRank;            
		private DataColumn columnURL;            
		private DataColumn columnLocation;            
		private DataColumn columnFileID;
	    
		internal SearchResultsTable() : base("SearchResults") 
		{
			this.InitClass();
		}
	    
		internal SearchResultsTable(DataTable table) : base(table.TableName) 
		{
			if ((table.CaseSensitive != table.DataSet.CaseSensitive)) 
			{
				this.CaseSensitive = table.CaseSensitive;
			}
			if ((table.Locale.ToString() != table.DataSet.Locale.ToString())) 
			{
				this.Locale = table.Locale;
			}
			if ((table.Namespace != table.DataSet.Namespace)) 
			{
				this.Namespace = table.Namespace;
			}
			this.Prefix = table.Prefix;
			this.MinimumCapacity = table.MinimumCapacity;
			this.DisplayExpression = table.DisplayExpression;
		}

        /// <summary>
        /// Gets the count.
        /// </summary>
        /// <value>The count.</value>
		public int Count {
			get {
				return this.Rows.Count;
			}
		}
	    
		internal DataColumn IndexColumn {
			get {
				return this.columnIndex;
			}
		}
	    
		internal DataColumn TitleColumn {
			get {
				return this.columnTitle;
			}
		}
	    
		internal DataColumn RankColumn {
			get {
				return this.columnRank;
			}
		}
	    
		internal DataColumn URLColumn {
			get {
				return this.columnURL;
			}
		}
	    
		internal DataColumn LocationColumn {
			get {
				return this.columnLocation;
			}
		}
	    
		internal DataColumn FileIDColumn {
			get {
				return this.columnFileID;
			}
		}

        /// <summary>
        /// Gets the <see cref="MSHelpLib.SearchResultsRow"/> at the specified index.
        /// </summary>
        /// <value></value>
		public SearchResultsRow this[int index] {
			get {
				return ((SearchResultsRow)(this.Rows[index]));
			}
		}

        /// <summary>
        /// Occurs when [search results row changed].
        /// </summary>
		public event SearchResultsRowChangeEventHandler SearchResultsRowChanged;

        /// <summary>
        /// Occurs when [search results row changing].
        /// </summary>
		public event SearchResultsRowChangeEventHandler SearchResultsRowChanging;

        /// <summary>
        /// Occurs when [search results row deleted].
        /// </summary>
		public event SearchResultsRowChangeEventHandler SearchResultsRowDeleted;

        /// <summary>
        /// Occurs when [search results row deleting].
        /// </summary>
		public event SearchResultsRowChangeEventHandler SearchResultsRowDeleting;

        /// <summary>
        /// Adds the search results row.
        /// </summary>
        /// <param name="row">The row.</param>
		public void AddSearchResultsRow(SearchResultsRow row) 
		{
			this.Rows.Add(row);
		}

        /// <summary>
        /// Adds the search results row.
        /// </summary>
        /// <param name="Title">The title.</param>
        /// <param name="Rank">The rank.</param>
        /// <param name="URL">The URL.</param>
        /// <param name="Location">The location.</param>
        /// <param name="FileID">The file ID.</param>
        /// <returns></returns>
		public SearchResultsRow AddSearchResultsRow(string Title, int Rank, string URL, string Location, int FileID) {
			SearchResultsRow rowSearchResultsRow = ((SearchResultsRow)(this.NewRow()));
			rowSearchResultsRow.ItemArray = new object[] {
					null,
					Title,
					Rank,
					URL,
					Location,
					FileID};
			this.Rows.Add(rowSearchResultsRow);
			return rowSearchResultsRow;
		}

        /// <summary>
        /// Returns an enumerator that iterates through a collection.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
        /// </returns>
		public System.Collections.IEnumerator GetEnumerator() {
			return this.Rows.GetEnumerator();
		}

        /// <summary>
        /// Clones the structure of the <see cref="T:System.Data.DataTable"/>, including all <see cref="T:System.Data.DataTable"/> schemas and constraints.
        /// </summary>
        /// <returns>
        /// A new <see cref="T:System.Data.DataTable"/> with the same schema as the current <see cref="T:System.Data.DataTable"/>.
        /// </returns>
        /// <PermissionSet>
        /// 	<IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/>
        /// 	<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/>
        /// 	<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence"/>
        /// </PermissionSet>
		public override DataTable Clone() {
			SearchResultsTable cln = ((SearchResultsTable)(base.Clone()));
			cln.InitVars();
			return cln;
		}
	    	    
		internal void InitVars() {
			this.columnIndex = this.Columns["Index"];
			this.columnTitle = this.Columns["Title"];
			this.columnRank = this.Columns["Rank"];
			this.columnURL = this.Columns["URL"];
			this.columnLocation = this.Columns["Location"];
			this.columnFileID = this.Columns["FileID"];
		}
	    
		private void InitClass() {
			this.columnIndex = new DataColumn("Index", typeof(int), null, System.Data.MappingType.Element);
			this.Columns.Add(this.columnIndex);
			this.columnTitle = new DataColumn("Title", typeof(string), null, System.Data.MappingType.Element);
			this.Columns.Add(this.columnTitle);
			this.columnRank = new DataColumn("Rank", typeof(int), null, System.Data.MappingType.Element);
			this.Columns.Add(this.columnRank);
			this.columnURL = new DataColumn("URL", typeof(string), null, System.Data.MappingType.Element);
			this.Columns.Add(this.columnURL);
			this.columnLocation = new DataColumn("Location", typeof(string), null, System.Data.MappingType.Element);
			this.Columns.Add(this.columnLocation);
			this.columnFileID = new DataColumn("FileID", typeof(int), null, System.Data.MappingType.Element);
			this.Columns.Add(this.columnFileID);
			this.columnIndex.AutoIncrement = true;
			this.columnIndex.AutoIncrementSeed = 1;
			this.columnIndex.AllowDBNull = false;
			this.columnTitle.AllowDBNull = false;
			this.columnRank.AllowDBNull = false;
			this.columnURL.AllowDBNull = false;
			this.columnLocation.AllowDBNull = false;
			this.columnFileID.AllowDBNull = true;
		}

        /// <summary>
        /// News the search results row.
        /// </summary>
        /// <returns></returns>
		public SearchResultsRow NewSearchResultsRow() {
			return ((SearchResultsRow)(this.NewRow()));
		}

        /// <summary>
        /// Creates a new row from an existing row.
        /// </summary>
        /// <param name="builder">A <see cref="T:System.Data.DataRowBuilder"/> object.</param>
        /// <returns>
        /// A <see cref="T:System.Data.DataRow"/> derived class.
        /// </returns>
		protected override DataRow NewRowFromBuilder(DataRowBuilder builder) {
			return new SearchResultsRow(builder);
		}

        /// <summary>
        /// </summary>
        /// <returns></returns>
		protected override System.Type GetRowType() {
			return typeof(SearchResultsRow);
		}

        /// <summary>
        /// Raises the <see cref="E:System.Data.DataTable.RowChanged"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Data.DataRowChangeEventArgs"/> that contains the event data.</param>
		protected override void OnRowChanged(DataRowChangeEventArgs e) {
			base.OnRowChanged(e);
			if ((this.SearchResultsRowChanged != null)) {
				this.SearchResultsRowChanged(this, new SearchResultsRowChangeEvent(((SearchResultsRow)(e.Row)), e.Action));
			}
		}

        /// <summary>
        /// Raises the <see cref="E:System.Data.DataTable.RowChanging"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Data.DataRowChangeEventArgs"/> that contains the event data.</param>
		protected override void OnRowChanging(DataRowChangeEventArgs e) {
			base.OnRowChanging(e);
			if ((this.SearchResultsRowChanging != null)) {
				this.SearchResultsRowChanging(this, new SearchResultsRowChangeEvent(((SearchResultsRow)(e.Row)), e.Action));
			}
		}

        /// <summary>
        /// Raises the <see cref="E:System.Data.DataTable.RowDeleted"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Data.DataRowChangeEventArgs"/> that contains the event data.</param>
		protected override void OnRowDeleted(DataRowChangeEventArgs e) {
			base.OnRowDeleted(e);
			if ((this.SearchResultsRowDeleted != null)) {
				this.SearchResultsRowDeleted(this, new SearchResultsRowChangeEvent(((SearchResultsRow)(e.Row)), e.Action));
			}
		}

        /// <summary>
        /// Raises the <see cref="E:System.Data.DataTable.RowDeleting"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Data.DataRowChangeEventArgs"/> that contains the event data.</param>
		protected override void OnRowDeleting(DataRowChangeEventArgs e) {
			base.OnRowDeleting(e);
			if ((this.SearchResultsRowDeleting != null)) {
				this.SearchResultsRowDeleting(this, new SearchResultsRowChangeEvent(((SearchResultsRow)(e.Row)), e.Action));
			}
		}

        /// <summary>
        /// Removes the search results row.
        /// </summary>
        /// <param name="row">The row.</param>
		public void RemoveSearchResultsRow(SearchResultsRow row) {
			this.Rows.Remove(row);
		}
	}

    /// <summary>
    /// 
    /// </summary>
	[System.Diagnostics.DebuggerStepThrough()]
	public class SearchResultsRow : DataRow {
	    
		private SearchResultsTable SearchResultsTable;
	    
		internal SearchResultsRow(DataRowBuilder rb) : 
				base(rb) {
			this.SearchResultsTable = ((SearchResultsTable)(this.Table));
		}

        /// <summary>
        /// Gets or sets the index.
        /// </summary>
        /// <value>The index.</value>
		public int Index {
			get {
				return ((int)(this[this.SearchResultsTable.IndexColumn]));
			}
			set {
				this[this.SearchResultsTable.IndexColumn] = value;
			}
		}

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
		public string Title {
			get {
				return ((string)(this[this.SearchResultsTable.TitleColumn]));
			}
			set {
				this[this.SearchResultsTable.TitleColumn] = value;
			}
		}

        /// <summary>
        /// Gets or sets the rank.
        /// </summary>
        /// <value>The rank.</value>
		public int Rank {
			get {
				return ((int)(this[this.SearchResultsTable.RankColumn]));
			}
			set {
				this[this.SearchResultsTable.RankColumn] = value;
			}
		}

        /// <summary>
        /// Gets or sets the URL.
        /// </summary>
        /// <value>The URL.</value>
		public string URL {
			get {
				return ((string)(this[this.SearchResultsTable.URLColumn]));
			}
			set {
				this[this.SearchResultsTable.URLColumn] = value;
			}
		}

        /// <summary>
        /// Gets or sets the location.
        /// </summary>
        /// <value>The location.</value>
		public string Location {
			get {
				return ((string)(this[this.SearchResultsTable.LocationColumn]));
			}
			set {
				this[this.SearchResultsTable.LocationColumn] = value;
			}
		}

        /// <summary>
        /// Gets or sets the file ID.
        /// </summary>
        /// <value>The file ID.</value>
		public int FileID {
			get {
				return ((int)(this[this.SearchResultsTable.FileIDColumn]));
			}
			set {
				this[this.SearchResultsTable.FileIDColumn] = value;
			}
		}
	}

    /// <summary>
    /// 
    /// </summary>
	[System.Diagnostics.DebuggerStepThrough()]
	public class SearchResultsRowChangeEvent : EventArgs 
	{    
		private SearchResultsRow eventRow;
	    
		private DataRowAction eventAction;

        /// <summary>
        /// Initializes a new instance of the <see cref="SearchResultsRowChangeEvent"/> class.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="action">The action.</param>
		public SearchResultsRowChangeEvent(SearchResultsRow row, DataRowAction action) 
		{
			this.eventRow = row;
			this.eventAction = action;
		}

        /// <summary>
        /// Gets the row.
        /// </summary>
        /// <value>The row.</value>
		public SearchResultsRow Row {
			get {
				return this.eventRow;
			}
		}

        /// <summary>
        /// Gets the action.
        /// </summary>
        /// <value>The action.</value>
		public DataRowAction Action {
			get {
				return this.eventAction;
			}
		}
	}
}
